﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BaseText;
using Srvtools;


public partial class ServicesSheet_UseCar : System.Web.UI.Page
{
    private Srvtools.WebDataSet WMaster;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request["id"] != null)
            {
                InitializeComponent();

                FLWebNavigator1.Visible = true;
                Master.DataSource = WMaster;
                WMaster.SetWhere(" Services_UseCars.UseCarId=" + Request["id"].ToString());


                string FlowFlag = Request["FlowFlag"].ToString();
                string EmployeeId = Request["EmpId"].ToString();
                if (FlowFlag == "" && Convert.ToInt32("0" + EmployeeId) == Convert.ToInt32(Srvtools.CliUtils.fLoginUser))
                {
                }
                else
                {
                    object o = FLWebNavigator1.NavControls["Comment"];
                    // FLWebNavigator1.NavControls.Clear();
                    FLWebNavigator1.NavControls.Add(o);
                }


                DataSet ds = WMaster.Execute("SELECT SYS_TODOLIST.LISTID FROM SYS_TODOLIST WHERE  SYS_TODOLIST.FORM_TABLE='Services_UseCars'" +
                    " and SYS_TODOLIST.FORM_KEYS='UseCarId' and  SYS_TODOLIST.FORM_PRESENTATION='UseCarId=" + Request["id"].ToString() + "'");
                if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                {
                    ImageButton imb = new ImageButton();
                    imb.ImageUrl = "../image/uipics/Comment_C.gif";
                    imb.ID = "i";
                    imb.Attributes.Add("onclick", "window.open('../InnerPages/FlowComment.aspx?LISTID=" + ds.Tables[0].Rows[0][0].ToString()
                        + "&ATTACHMENTS=', '', 'resizable=yes,scrollbars=yes,width=645,height=400,top=100,left=200');return false");
                    FLWebNavigator1.Controls.Add(imb);
                }
            }
            else
            {
                InitializeComponent();
                Master.DataSource = WMaster;
            }

            MasterPage_MasterPage master = (MasterPage_MasterPage)this.Page.Master;
            master.HelpHref = "~/Help/ServicesSheet/用车申请.htm";
            master.PageName = "用车申请";
            master.PicUrl = "";
            master.IntiBar();
        }
    }

    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ServicesSheet_UseCar));
        this.WMaster = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).BeginInit();
        // 
        // WMaster
        // 
        this.WMaster.Active = true;
        this.WMaster.AlwaysClose = true;
        this.WMaster.DeleteIncomplete = true;
        this.WMaster.Guid = null;
        this.WMaster.LastKeyValues = null;
        this.WMaster.Locale = new System.Globalization.CultureInfo("zh-CN");
        this.WMaster.PacketRecords = 100;
        this.WMaster.Position = -1;
        this.WMaster.RemoteName = "ServiceSheet.Services_UseCars";
        this.WMaster.ServerModify = true;
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).EndInit();

    }

    protected void wfvMaster_DataBound(object sender, EventArgs e)
    {
        if (this.wfvMaster.CurrentMode == FormViewMode.ReadOnly)
        {
            CheckBox cbox = (CheckBox)this.wfvMaster.FindControl("CheckBox2");
            if (cbox != null)
                cbox.Attributes.Add("onclick", "return false");
        }
    }

    protected string GetEmpId()
    {
        String str = Srvtools.CliUtils.GetValue("_UserCode")[1].ToString();
        str = int.Parse(str).ToString();
        return str;
    }

    protected string GetEmpId2()
    {
        String str = Srvtools.CliUtils.GetValue("_UserCode")[1].ToString();
        str = int.Parse(str).ToString();
        return str;
    }

    protected void FLWebNavigator1_BeforeCommand(object sender, Srvtools.BeforeCommandArgs e)
    {
        if (e.CommandName == "cmdApply")
        {
            // if (CheckCar()==true ) e.Cancel = true;
        }
    }

    private bool CheckCar()
    {
        WebRefVal CarId = (WebRefVal)this.wfvMaster.FindControl("WebRefVal2");
        string strCarId = CarId.BindingValue;

        ZLTextBox UCDate = (ZLTextBox)this.wfvMaster.FindControl("ZLTextBox1");
        string strUCDate = UCDate.Text;

        WebDropDownList StartHour = (WebDropDownList)this.wfvMaster.FindControl("WebDropDownList1");
        string strStartHour = StartHour.SelectedValue;

        WebDropDownList EndHour = (WebDropDownList)this.wfvMaster.FindControl("WebDropDownList3");
        string strEndHour = EndHour.SelectedValue;

        TextBox CarAppId = (TextBox)this.wfvMaster.FindControl("UseCarIdTextBox");
        string strCarAppId = CarAppId.Text;

        object[] objParam = new object[5];
        objParam[0] = strCarId;
        objParam[1] = strUCDate;
        objParam[2] = strStartHour;
        objParam[3] = strEndHour;
        objParam[4] = strCarAppId;

        bool ApplExist = false;

        object[] myRet = CliUtils.CallMethod("ServiceSheet", "GetUseCarsApplicate", objParam);
        if (myRet != null && (int)myRet[0] == 0)
        {

            ApplExist = (bool)myRet[1];
            string Msg = (string)myRet[2];
            if (ApplExist == true) ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "alert('" + Msg + "')", true);

        }
        return ApplExist;
    }
    protected void FLWebNavigator1_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "cmdApply")
        {
            if (IsPostBack == true)
            {
                if (Request["id"] != null)
                {
                    //Master.Reload();
                    Master.SetWhere("Services_UseCars.UseCarId = " + Request["id"].ToString());
                }
                else
                {
                    //Master.Reload();
                }
            }

        }
    }
}
